defmodule MatchingBrackets do
  @doc """
  Checks that all the brackets and braces in the string are matched correctly, and nested correctly
  """
  @check_brackets ~r/((\((?:[^\{\})(\[\]]+|(?R))*+\))|(\[(?:[^\{\})(\[\]]+|(?R))*+\])|(\{(?:[^\{\})(\[\]]+|(?R))*+\}))/

  @spec check_brackets(String.t()) :: boolean
  def check_brackets(str) do
    # stack chk-pop-clean?

    Regex.replace(@check_brackets, str, "")
    |> IO.inspect
    |> String.contains?(["[", "]", "{", "}", "(", ")"])
    #|> IO.inspect
    |> (&!/1).()

  end


end
